const Controller = require('egg').Controller

class GoodsController extends Controller {
  // 新增商品
  async add() {
    const params = this.ctx.request.body
    let res = await this.service.goods.add({
      ...params,
      user_id: this.ctx.user.id
    })
    this.ctx.body = this.ctx.returnStatus.SUCCESS(res)
  }
  // 获取商品列表
  async list() {
    const params = this.ctx.query
    let res = await this.service.goods.list({
      ...params
    })
    this.ctx.body = this.ctx.returnStatus.SUCCESS(res)
  }
  // 添加购物车
  async addCart() {
    const params = this.ctx.request.body
    let res = await this.service.goods.addCart({
      ...params,
      user_id: this.ctx.user.id
    })
    this.ctx.body = this.ctx.returnStatus.SUCCESS(res)
  }
  // 获取购物车
  async getCart() {
    const params = this.ctx.query
    let res = await this.service.goods.getCart({
      ...params,
      user_id: this.ctx.user.id
    })
    this.ctx.body = this.ctx.returnStatus.SUCCESS(res)
  }
  // 清除购物车
  async clearCart() {
    const params = this.ctx.request.body
    let res = await this.service.goods.clearCart({
      ...params,
      user_id: this.ctx.user.id
    })
    this.ctx.body = this.ctx.returnStatus.SUCCESS(res)
  }
  // 获取商家商品列表
  async getStoreList() {
    const params = this.ctx.query
    let res = await this.service.goods.list({
      ...params,
      user_id: this.ctx.user.id
    })
    this.ctx.body = this.ctx.returnStatus.SUCCESS(res)
  }
  // 删除商品
  async remove() {
    const params = this.ctx.request.body
    let res = await this.service.goods.remove({
      id: params.id,
      user_id: this.ctx.user.id
    })
    this.ctx.body = this.ctx.returnStatus.SUCCESS(res)
  }
}

module.exports = GoodsController
